const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");
/**
 * @param {number[]} nums
 * @return {boolean}
 */
var canJump = function (nums) {
  if (!nums.length || nums.length === 1) return true;
  for (let i = 0; i < nums.length; i++) {
    let p = nums[i];
    if (!p) return i === nums.length - 1;
    let index = 1;
    for (let y = 2; y < p + 1; y++) {
      const oldN = nums[i + index] + index;
      if (nums[i + y] + y > oldN) {
        index = y;
      }
    }
    i += index - 1;
  }
  return true;
};
let nums = [2, 0];
timeL(canJump, [nums]);
